package wykop.analyze;

import java.util.Set;

import wykop.page.WykopComment;

import com.google.common.collect.Sets;

public class NumberOfTokens extends NumericCommentFeature {

	private final String name;
	private final Set<String> tokens;

	public NumberOfTokens(final String name, final String... tokens) {
		super();
		this.name = name;
		this.tokens = Sets.newHashSet(tokens);
	}
	
	public NumberOfTokens(final String name, final Set<String> tokens) {
		super();
		this.name = name;
		this.tokens = Sets.newHashSet(tokens);
	}

	@Override
	public String name() {
		return "NumberOfTokens" + name;
	}

	@Override
	protected int value(final WykopComment comment) {

		int count = 0;

		for (final String token : WordBreaker.tokens(comment.getText())) {
			if (tokens.contains(token.toLowerCase())) {
				count++;
			}
		}

		return count;

	}

}
